﻿using Microsoft.Office.Interop.Excel;
using MiniExcelLibs;
using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup;
using PanhuaWin.系统管理;
using PanhuaWin.通用;
//using Pomelo.EntityFrameworkCore.MySql;
using StackExchange.Redis;
using Sunny.UI;
using Sunny.UI.Win32;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.UI;
using System.Windows.Controls;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using DataTable = System.Data.DataTable;

namespace PanhuaWin.车间
{
    public partial class Form酸洗计划维护 : UIPage
    {


        string 部门编号;
        string FormGuid;
        string form部门名称;
        string form部门编号;
        int 开始行;
        int 开始列;
        int 结束行;
        int 结束列;

        string 部门guid;
        string FormWorkType = "酸连轧";


        public string 产线编号 { get; private set; }
        public string 产线名称 { get; private set; }

        public Form酸洗计划维护()
        {
            InitializeComponent();
        }

        private void splitContainer3_Panel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void Form酸洗计划维护_Load(object sender, EventArgs e)
        {
            this.uiTextBox工厂名称.Text = pub.全局工厂名称;

            this.uiDatePicker1.Value = DateTime.Today.AddMonths(-1);
            this.uiDatePicker2.Value = DateTime.Today;
            this.uiDatePicker计划日期.Value = DateTime.Today;
            pub.ListWorkLine(pub.全局工厂编号, FormWorkType, this.uiComboBox产线);
            pub.ListSteelAll(this.uiComboBox材质1);
            FormGuid = Guid.NewGuid().ToString();
            DeleteTempPlan();
        }

        private void DeleteTempPlan()
        {
            string sql;
            sql = "delete Temp_酸洗计划 where mac='" + pub.getMac() + "'";
            pub.ExecuteSql(pub.ConnectionString, sql, "进入界面时删除Temp_酸洗计划");
        }


        private void uiTextBox库位搜索1_TextChanged(object sender, EventArgs e)
        {
            //Do库位刷新1(this.uiComboBox仓库编号.SelectedValue.ToString());
        }


        private void uiButton查询_Click(object sender, EventArgs e)
        {
            //显示所有仓库收到的原料
            ListData();
            ListTempPlan();


        }

        private void ListData()
        {
            try
            {
                string sql;




                string WorkShopCode = pub.全局工厂编号;
                //if (this.uiComboBox仓库编号.SelectedText == "")
                //{
                //    MessageBox.Show("仓库要选择,请重试!", "提示", MessageBoxButtons.OK);
                //    return;
                //}

                string WarehouseCode = "F11";
                string StorageLocation = "";
                sql = "SELECT    row_number() over(order by VolumeCode) 序号, CreateDate 入库日期 , guid, Bguid, DocCode 入库单号, RowNumber, WorkShopCode 工厂编号, WarehouseCode 仓库编号, StorageLocation 库位编号,  ";
                sql += " T_CONTRACT_CODE, T_ORDER, T_GOOD_UNIT, T_GOOD_NUM, T_GOOD_PRICE, T_GOOD_MONEY, VolumeCode,   ";
                sql += " VolumeCodeNew 新卷号, InventoryCode 存货编号, Size 规格型号, Thick, Width, Material 材质, Address 产地, Weight 重量, CID, Virtual FROM      View_能被酸洗计划1 where 1=1  ";
                sql += " and WorkShopCode='" + WorkShopCode + "'";
                sql += " and WarehouseCode='" + WarehouseCode + "'";

                if (this.uiTextBox产地1.Text != "")
                {
                    sql += " and Address like '" + this.uiTextBox产地1.Text.Trim().Replace("--", "") + "'";

                }
                if (this.uiTextBox卷号.Text != "")
                {
                    sql += " and VolumeCodeNew like '%" + this.uiTextBox卷号.Text.Trim().Replace("--", "") + "%'";
                }
                if (this.uiTextBox规格型号1.Text != "")
                {
                    sql += " and Size like '" + this.uiTextBox规格型号1.Text.Trim().Replace("--", "") + "'";
                }
                if (this.uiComboBox材质1.SelectedText != "全部")
                {
                    sql += " and Material='" + this.uiComboBox材质1.SelectedText + "'";
                }
                if (this.uiTextBox库位.Text != "")
                {
                    sql += " and StorageLocation = '" + this.uiTextBox库位.Text.Trim().Replace("--", "") + "'";
                }

                System.Data.DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
                this.uiDataGridView待选.AutoGenerateColumns = false;
                this.uiDataGridView待选.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
                this.uiDataGridView待选.DataSource = tb;
                this.uiDataGridView待选.Refresh();
            }
            catch
            {

            }
        }




        private void uiLabel4_Click(object sender, EventArgs e)
        {

        }

        private void uiButton导出_Click(object sender, EventArgs e)
        {
            string path;
            this.saveFileDialog1.Filter = "Excel 文件(*.xlsx)|*.xlsx ";

            try
            {
                string sql;
                string WorkShopCode = pub.全局工厂编号;

                string WarehouseCode = "F11";

                sql = "SELECT    row_number() over(order by VolumeCode) 序号, WorkShopCode 工厂编号, CreateDate 入库日期 ,WarehouseCode 仓库编号,  DocCode 入库单号,  StorageLocation 库位编号,  ";
                sql += "  InventoryCode 存货编号, Size 规格型号,Material 材质, Address 产地,   ";
                sql += " VolumeCodeNew 新卷号,  Weight 重量  FROM      View_能被酸洗计划1 where 1=1  ";
                sql += " and WorkShopCode='" + WorkShopCode + "'";
                sql += " and WarehouseCode='" + WarehouseCode + "'";

                if (this.uiTextBox产地1.Text != "")
                {
                    sql += " and Address like '" + this.uiTextBox产地1.Text.Trim().Replace("--", "") + "'";

                }
                if (this.uiTextBox卷号.Text != "")
                {
                    sql += " and VolumeCodeNew like '%" + this.uiTextBox卷号.Text.Trim().Replace("--", "") + "%'";
                }
                if (this.uiTextBox规格型号1.Text != "")
                {
                    sql += " and Size like '" + this.uiTextBox规格型号1.Text.Trim().Replace("--", "") + "'";
                }
                if (this.uiComboBox材质1.SelectedText != "全部")
                {
                    sql += " and Material='" + this.uiComboBox材质1.SelectedText + "'";
                }

                System.Data.DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
                if (this.saveFileDialog1.ShowDialog(this) == DialogResult.OK)
                {
                    path = this.saveFileDialog1.FileName;
                    if (!File.Exists(path))
                    {
                        MiniExcel.SaveAs(path, tb, true, "sheet1", ExcelType.XLSX);
                    }
                    else
                    {
                        MessageBox.Show("文件已经存在,请重试!", "提示", MessageBoxButtons.OK);
                        return;
                    }

                }

            }
            catch (Exception ex)
            {

            }

        }

        private void uiDataGridView待选_MouseDown(object sender, MouseEventArgs e)
        {

        }

        private void uiDataGridView待选_MouseUp(object sender, MouseEventArgs e)
        {

        }

        private void uiDataGridView待选_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
        {
            开始行 = e.RowIndex;
        }

        private void uiDataGridView待选_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
        {
            结束行 = e.RowIndex;
        }


        private void uiCheckBox选中行打钩_CheckedChanged(object sender, EventArgs e)
        {
            if (开始行 <= 结束行)
            {

            }
            else
            {
                int p = 开始行;
                开始行 = 结束行;
                结束行 = p;
            }
            if (开始行 >= 0 && 结束行 >= 0)
            {
                for (int i = 开始行; i <= 结束行; i++)
                {
                    this.uiDataGridView待选.Rows[i].Cells["C选中"].Value = this.uiCheckBox选中行打钩.Checked;
                }
            }

        }

        private void uiButtont添加选中_Click(object sender, EventArgs e)
        {
            开始行 = -1;
            结束行 = -1;
            string VolumeCodeNew;
            string guid;
            string outPutSize = this.uiTextBox轧制规格.Text;
            string productSize = this.uiTextBox成品规格.Text;

            if (!pub.IsRightSize(outPutSize) && outPutSize != "")
            {
                MessageBox.Show("轧制规格要么空着，要么要填对,请重试!", "提示", MessageBoxButtons.OK);
                return;
            }
            if (!pub.IsRightSize(productSize) && productSize != "")
            {
                MessageBox.Show("成品规格要么空着，要么要填对,请重试!", "提示", MessageBoxButtons.OK);
                return;
            }
            if (this.uiComboBox产线.SelectedText == "")
            {
                MessageBox.Show("产线要选择,请重试!", "提示", MessageBoxButtons.OK);
                return;
            }
            产线编号 = this.uiComboBox产线.SelectedValue.ToString();
            产线名称 = this.uiComboBox产线.SelectedText;
            if (this.uiComboBox去向.SelectedText == "")
            {
                MessageBox.Show("去向要选择,请重试!", "提示", MessageBoxButtons.OK);
                return;
            }
            string nextWorkType = this.uiComboBox去向.SelectedText;
            string remark = this.uiTextBox备注.Text.Trim().Replace("--", "");
            guid = FormGuid;
            if (this.uiDataGridView待选.Rows.Count > 0)
            {

                for (int j = 0; j < this.uiDataGridView待选.Rows.Count; j++)
                {
                    DataGridViewRow urow = this.uiDataGridView待选.Rows[j];
                    if (urow.Cells["C选中"].Value != null)
                    {
                        if ((bool)urow.Cells["C选中"].Value)
                        {
                            string 热轧规格 = urow.Cells["C规格型号"].Value.ToString();
                            string 产地 = urow.Cells["C产地"].Value.ToString();
                            string 热轧批号 = urow.Cells["C新卷号"].Value.ToString();
                            string 重量 = urow.Cells["C重量"].Value.ToString();
                            string 轧制规格 = uiTextBox轧制规格.Text;
                            string 产线名称 = this.uiComboBox产线.SelectedText;
                            string 去向 = uiComboBox去向.Text;
                            string 材质 = urow.Cells["C材质"].Value.ToString();

                            string 客户 = this.uiTextBox客户.Text.Trim().Replace("--", "");
                            string 成品规格 = uiTextBox成品规格.Text;
                            string 备注 = uiTextBox备注.Text;
                            InsertTemp计划(FormGuid, 热轧规格, 产地, 热轧批号, 重量, 轧制规格, 产线名称, 去向, 材质, 客户, 成品规格, 备注);
                        }
                    }
                }
                //重新刷新
                ListData();
                ListTempPlan();
            }
        }
        private void ListTempPlan()
        {
            string sql = @"SELECT  row_number() over(order by  时间) 序号, WorkShopGuid, WorkShopCode, DepartGuid, DepartCode, WorkLineCode, WorkLineName 产线名称, WorkDate, RowNumber,
               Originalsize 热轧规格, Address 产地, VolumeCode , VolumeCodeNew 热轧批号, Weight 重量, OutputSize 轧制规格, ProductSize 成品规格,NextWorkType 去向, Material 材质, StorageLocation 库位, MAC,
               时间,remark 备注,customer 客户 FROM Temp_酸洗计划  where guid='" + FormGuid + "'   ";
            System.Data.DataTable tb1 = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb1.Rows.Count > 0)
            {
                this.uiDataGridView已选.AutoGenerateColumns = false;
                this.uiDataGridView已选.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
                this.uiDataGridView已选.DataSource = tb1;
                this.uiDataGridView已选.Refresh();
            }
            else
            {
                this.uiDataGridView已选.DataSource = null;
                this.uiDataGridView已选.Refresh();
            }
        }
        private void uiButton清空_Click(object sender, EventArgs e)
        {
            string sql;
            sql = "delete Temp_酸洗计划 where mac ='" + pub.getMac() + "'";
            pub.ExecuteSql(pub.ConnectionString, sql, "清空临时酸洗计划表");
            ListData();
            ListTempPlan();
        }
        private void uiComboBox产线_SelectedValueChanged(object sender, EventArgs e)
        {
            string workLineCode;
            if (this.uiComboBox产线.SelectedValue != null)
            {
                workLineCode = this.uiComboBox产线.SelectedValue.ToString();
                pub.ListWorkType(pub.全局工厂编号, "酸洗", this.uiComboBox去向);
            }
        }
        private void uiButton取消选中_Click(object sender, EventArgs e)
        {
            if (this.uiDataGridView已选.Rows.Count > 0)
            {
                int k = 1;
                for (int j = 0; j < this.uiDataGridView已选.Rows.Count; j++)
                {
                    DataGridViewRow urow = this.uiDataGridView已选.Rows[j];
                    if (urow.Cells["D选中"].Value != null)
                    {
                        if ((bool)urow.Cells["D选中"].Value)
                        {
                            string guid = FormGuid;
                            string VolumeCodeNew = urow.Cells["D热轧批号"].Value.ToString();
                            DeleteTemp计划(guid, VolumeCodeNew);
                        }
                    }
                }
                //重新刷新
                ListData();
                ListTempPlan();
            }
        }

        private void DeleteTemp计划(string guid, string volumeCodeNew)
        {
            string sql;
            sql = "delete Temp_酸洗计划 where guid='" + guid + "' and volumeCodeNew='" + volumeCodeNew + "'";
            pub.ExecuteSql(pub.ConnectionString, sql, "DeleteTemp计划-酸洗计划");
        }

        private void uiDataGridView已选_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                if (this.uiDataGridView已选.Columns[e.ColumnIndex].Name == "D取消")
                {
                    DataGridViewRow urow = this.uiDataGridView已选.Rows[e.RowIndex];
                    string guid = FormGuid;
                    string VolumeCodeNew = urow.Cells["D热轧批号"].Value.ToString();
                    DeleteTemp计划(guid, VolumeCodeNew);
                    //重新刷新
                    ListData();
                    ListTempPlan();
                }
            }
        }

        private void uiButton导出模板_Click(object sender, EventArgs e)
        {
            string path;
            string sql = @"SELECT  ''序号,''热卷规格,''产地,''热卷批号,''重量,''酸轧规格,''产线名称,''去向,''材质,''客户,''成品规格,''备注 FROM Temp_酸洗计划  where 1=2    ";
            saveFileDialog1.Filter = "Excel文件 (*.XLSX)|*.XLSX";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (this.saveFileDialog1.ShowDialog(this) == DialogResult.OK)
            {
                path = this.saveFileDialog1.FileName;
                if (!File.Exists(path))
                {
                    MiniExcel.SaveAs(path, tb, true, "sheet1", ExcelType.XLSX);
                }
                else
                {
                    MessageBox.Show("文件已经存在,请重试!", "提示", MessageBoxButtons.OK);
                    return;
                }

            }
        }

        private void uiDataGridView已选_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            //更新内容

            if (this.uiDataGridView已选.Rows.Count > 0)
            {

                string sql;
                int j = e.RowIndex;
                //for (int j = 0; j < this.uiDataGridView已选.Rows.Count; j++)
                //{
                DataGridViewRow urow = this.uiDataGridView已选.Rows[j];
                string outPutSize = urow.Cells["D轧制规格"].Value.ToString().Trim().Replace("--", "");
                string productSize = urow.Cells["D成品规格"].Value.ToString().Trim().Replace("--", "");

                if (!pub.IsRightSize(outPutSize) && outPutSize != "")
                {
                    MessageBox.Show("第" + (j + 1).ToString() + "行的轧制规格要么空着，要么要填对,请重试!", "提示", MessageBoxButtons.OK);

                    return;
                }
                if (!pub.IsRightSize(productSize) && productSize != "")
                {
                    MessageBox.Show("第" + (j + 1).ToString() + "行的成品规格要么空着，要么要填对,请重试!", "提示", MessageBoxButtons.OK);

                    return;

                }
                string nextWorkType = urow.Cells["D去向"].Value.ToString().Trim().Replace("--", "");
                if (!pub.IsRightNextWorkType(pub.全局工厂编号, FormWorkType, nextWorkType))
                {
                    MessageBox.Show("第" + (j + 1).ToString() + "行的去向有问题,请重试!", "提示", MessageBoxButtons.OK);

                    return;

                }

                string remark = urow.Cells["D备注"].Value.ToString().Trim().Replace("--", "");
                string volumeCodeNew = urow.Cells["D热轧批号"].Value.ToString().Trim().Replace("--", "");
                sql = " update Temp_酸洗计划 set OutputSize='" + outPutSize + "',ProductSize='" + productSize + "',NextWorkType='" + nextWorkType + "' ,Remark='" + remark + "'";

                sql += " where guid='" + FormGuid + "' and VolumeCodeNew='" + volumeCodeNew + "'";
                pub.ExecuteSql(pub.ConnectionString, sql, "Temp_酸洗计划手动更新");
                //}

            }
        }

        private void uiButton保存_Click(object sender, EventArgs e)
        {
            string sql;
            sql = "select guid, WorkShopGuid, WorkShopCode, DepartGuid, DepartCode, WorkLineCode, WorkLineName, WorkDate, ";
            sql += " RowNumber, Originalsize, Address, VolumeCode, VolumeCodeNew, Weight, OutputSize, ProductSize, NextWorkType, Remark, Material,  ";
            sql += " StorageLocation, MAC from Temp_酸洗计划 where guid='" + FormGuid + "' order by RowNumber ";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);

            if (tb.Rows.Count > 0)
            {    //先  检查
                for (int i = 0; i < tb.Rows.Count; i++)
                {
                    string VolumeCodeNew = tb.Rows[i]["VolumeCodeNew"].ToString().Trim().Replace("--", "");

                    string outPutSize = tb.Rows[i]["OutputSize"].ToString().Trim().Replace("--", "");
                    if (!pub.IsRightSize(outPutSize) && outPutSize != "")
                    {
                        MessageBox.Show(VolumeCodeNew + "的轧制规格要么空着，要么要填对,请重试!", "提示", MessageBoxButtons.OK);

                        return;
                    }
                    string productSize = tb.Rows[i]["ProductSize"].ToString().Trim().Replace("--", "");
                    if (!pub.IsRightSize(productSize) && productSize != "")
                    {
                        MessageBox.Show(VolumeCodeNew + "的成品规格要么空着，要么要填对,请重试!", "提示", MessageBoxButtons.OK);

                        return;
                    }
                    string nextWorkType = tb.Rows[i]["NextWorkType"].ToString().Trim().Replace("--", "");
                    if (!pub.IsRightNextWorkType(pub.全局工厂编号, FormWorkType, nextWorkType))
                    {
                        MessageBox.Show(VolumeCodeNew + "的去向有问题,请重试!", "提示", MessageBoxButtons.OK);

                        return;

                    }
                    if (pub.IsInPlan(pub.全局工厂编号, FormWorkType, VolumeCodeNew))
                    {
                        MessageBox.Show(VolumeCodeNew + "的卷号已经有计划了,请重试!", "提示", MessageBoxButtons.OK);
                        return;
                    }
                    //string storageLocation = tb.Rows[i]["StorageLocation"].ToString().Trim().Replace("--", "");
                    //if (!pub.IsVolumeInStorageLocation(pub.全局工厂编号, VolumeCodeNew, storageLocation))
                    //{
                    //    MessageBox.Show("第" + (i + 1).ToString() + "行的卷号,已经不存在库位中,请重试!", "提示", MessageBoxButtons.OK);
                    //    return;
                    //}
                }
            }
            try
            {
                ///再塞入
                int r1 = 0;
                int r2 = 0;

                sql = " insert into   Bus_PlanPickling (guid, WorkShopGuid, WorkShopCode, DepartGuid, DepartCode, WorkLineCode, WorkLineName, WorkDate, ";
                sql += " RowNumber, Originalsize, Address, VolumeCode, VolumeCodeNew, Weight, OutputSize, ProductSize, NextWorkType, Remark, Material,  ";
                sql += " StorageLocation, MAC, CreateID, Creator, CreateDate,Customer)   ";
                sql += " select newid(), WorkShopGuid, WorkShopCode, DepartGuid, DepartCode, WorkLineCode, WorkLineName, WorkDate, ";
                sql += " row_number() over(order by  时间) RowNumber, Originalsize, Address, VolumeCode, VolumeCodeNew, Weight, OutputSize, ProductSize, NextWorkType, Remark, Material,  ";
                sql += "  StorageLocation, MAC,'" + pub.sys_user.User_Id + "' ,'" + pub.sys_user.UserName + "',getdate(),Customer from Temp_酸洗计划 where guid='" + FormGuid + "'   ";
                r1 = pub.ExecuteSql(pub.ConnectionString, sql, "从Temp_酸洗计划塞入Bus_PlanPickling");
                ///清理临时表
                sql = "delete Temp_酸洗计划 where mac ='" + pub.getMac() + "' or  guid='" + FormGuid + "' ";
                r2 = pub.ExecuteSql(pub.ConnectionString, sql, "清空临时酸洗计划表");
                if (r1 * r2 != 0)
                {
                    ListData();
                    ListTempPlan();
                    MessageBox.Show("酸洗计划保存成功!", "提示", MessageBoxButtons.OK);
                    return;
                }
                else
                {
                    ListData();
                    ListTempPlan();
                    MessageBox.Show("酸洗计划保存失败!", "提示", MessageBoxButtons.OK);
                    return;
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show("酸洗计划保存失败!异常信息是:" + ex.Message, "提示", MessageBoxButtons.OK);
            }


        }
        private void uiButton导入_Click(object sender, EventArgs e)
        {


            try
            {
                string path;
                //openFileDialog1.InitialDirectory = Application.ExecutablePath;
                //openFileDialog1.Filter = "Excel文件|*.xlsx";
                //openFileDialog1.FilterIndex = 2;
                openFileDialog1.RestoreDirectory = true;

                this.openFileDialog1.Filter = "Excel 文件(*.xlsx)|*.xlsx";
                if (this.openFileDialog1.ShowDialog(this) == DialogResult.OK)
                {
                    path = this.openFileDialog1.FileName;
                    DataTable table = (DataTable)MiniExcel.QueryAsDataTable(path, useHeaderRow: true);
                    if (table.Rows.Count > 0)
                    {
                        if (FormGuid == "")
                        {
                            FormGuid = Guid.NewGuid().ToString();
                        }
                        for (int i = 0; i < table.Rows.Count; i++)
                        {
                            //序号,热轧规格,产地,热轧批号,重量,轧制规格,产线名称去向,材质,库位,客户,产品规格,备注
                            string 热轧规格 = table.Rows[i]["热卷规格"].ToString();
                            string 产地 = table.Rows[i]["产地"].ToString();
                            string 热轧批号 = table.Rows[i]["热卷批号"].ToString();
                            string 重量 = table.Rows[i]["重量"].ToString();
                            string 轧制规格 = table.Rows[i]["酸轧规格"].ToString();
                            string 产线名称 = table.Rows[i]["产线名称"].ToString();
                            string 去向 = table.Rows[i]["去向"].ToString();
                            string 材质 = table.Rows[i]["材质"].ToString();

                            string 客户 = table.Rows[i]["客户"].ToString();
                            string 成品规格 = table.Rows[i]["成品规格"].ToString();
                            string 备注 = table.Rows[i]["备注"].ToString();

                            InsertTemp计划(FormGuid, 热轧规格, 产地, 热轧批号, 重量, 轧制规格, 产线名称, 去向, 材质, 客户, 成品规格, 备注);
                        }
                        ListTempPlan();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("添加失败了!" + ex.ToString(), "提示", MessageBoxButtons.OK);
                return;
            }
        }

        private void InsertTemp计划(string formGuid, string 热轧规格, string 产地, string 热轧批号, string 重量, string 轧制规格, string 产线名称, string 去向, string 材质, string 客户, string 成品规格, string 备注)
        {
            string sql;

            sql = " select VolumeCodeNew from Temp_酸洗计划 where VolumeCodeNew ='" + 热轧批号 + "' ";
            sql += " union all   ";
            sql += " select OriginalVolumeNew from Bus_PicklingOriginal where OriginalVolumeNew ='" + 热轧批号 + "'";
            sql += " union all   ";
            sql += " select VolumeCodeNew from  Bus_PlanPickling where VolumeCodeNew ='" + 热轧批号 + "'";
            System.Data.DataTable tb1 = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb1.Rows.Count > 0)
            {
                //说明有计划或者使用了
                MessageBox.Show($"{热轧批号}已经被导入了");
            }
            else
            {

                Dic_Depart dic_Depart = pub.GetDepartByWorkLine(产线名称);
                if (dic_Depart != null)
                {
                    部门编号 = dic_Depart.DepartCode;

                    部门guid = dic_Depart.guid.ToString();

                }
                sql = " insert into Temp_酸洗计划 (guid, WorkShopGuid, WorkShopCode, DepartGuid, DepartCode, WorkLineCode, WorkLineName, WorkDate, " +
                      " Originalsize, Address, VolumeCode, VolumeCodeNew, Weight, OutputSize,ProductSize, NextWorkType, Material,   MAC, 时间,remark,Customer)";
                sql += " select '" + formGuid + "','" + pub.全局工厂guid + "','" + pub.全局工厂编号 + "','" + 部门guid + "','" + 部门编号 + "','" + 产线编号 + "',";
                sql += " '" + 产线名称 + "','" + this.uiDatePicker计划日期.Value.ToString("yyyy-MM-dd") + "','" + 热轧规格 + "' ,'" + 产地 + "', VolumeCode, '" + 热轧批号 + "', '" + 重量 + "',";
                sql += " '" + 轧制规格 + "' , '" + 成品规格 + "' , '" + 去向 + "','" + 材质 + "',  '" + pub.getMac() + "' ,getdate(),'" + 备注 + "','" + 客户 + "' ";
                sql += " from Bus_StockInVolume where VolumeCodeNew ='" + 热轧批号 + "'";
             int r =   pub.ExecuteSql(pub.ConnectionString, sql, "塞入Temp_酸洗计划");
            }
        }



        private void uiComboBox产线_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.uiComboBox产线.SelectedValue.ToString() != "")
            {
                pub.ListWorkType(pub.全局工厂编号, FormWorkType, this.uiComboBox去向);
                Dic_Depart dic_Depart = pub.GetDepartByWorkLine(this.uiComboBox产线.SelectedText);
                if (dic_Depart != null)
                {
                    form部门名称 = dic_Depart.DepartName;
                    form部门编号 = dic_Depart.DepartCode;
                }
                else
                {
                    form部门名称 = "";
                    form部门编号 = "";
                }

            }
            pub.ListWorkType(pub.全局工厂编号, "酸连轧", this.uiComboBox去向);

        }


        private void uiDataGridView已选_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
        {
            开始行 = e.RowIndex;
            开始列 = e.ColumnIndex;
        }

        private void uiDataGridView已选_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
        {
            结束行 = e.RowIndex;
            结束列 = e.ColumnIndex;
        }

        private void uiButton批量修改_Click(object sender, EventArgs e)
        {
            string sql;
            string 卷号;
            if (开始行 >= 0 && 结束行 >= 0)
            {
                if (开始行 > 结束行)
                {
                    int k = 开始行;
                    开始行 = 结束行;
                    结束行 = k;
                }
                if (结束列 == 开始列)
                {
                    if (this.uiDataGridView已选.Columns[结束列].Name == "D轧制规格")
                    {
                        string 轧制规格 = this.uiTextBox轧制规格.Text.Trim().Replace("--", "");
                        if (轧制规格 != "")
                        {
                            if (!pub.IsRightSize(轧制规格))
                            {
                                MessageBox.Show("轧制规格填写错误不能批量修改", "提示", MessageBoxButtons.OK);
                                return;
                            }
                        }

                        for (int i = 开始行; i <= 结束行; i++)
                        {
                            卷号 = this.uiDataGridView已选.Rows[i].Cells["D热轧批号"].Value.ToString();
                            sql = "update Temp_酸洗计划 set OutputSize ='" + 轧制规格 + "' where VolumeCodeNew ='" + 卷号 + "' and guid='" + FormGuid + "'";
                            pub.ExecuteSql(pub.ConnectionString, sql, "批量修改=酸洗临时表");
                            this.uiDataGridView已选.Rows[i].Cells["D轧制规格"].Value = 轧制规格;
                        }

                    }
                    else if (this.uiDataGridView已选.Columns[结束列].Name == "D去向")
                    {
                        string 去向;
                        去向 = this.uiComboBox去向.SelectedText;

                        for (int i = 开始行; i <= 结束行; i++)
                        {
                            卷号 = this.uiDataGridView已选.Rows[i].Cells["D热轧批号"].Value.ToString();
                            sql = "update Temp_酸洗计划 set NextWorkType ='" + 去向 + "' where VolumeCodeNew ='" + 卷号 + "' and guid='" + FormGuid + "'";
                            pub.ExecuteSql(pub.ConnectionString, sql, "批量修改=酸洗临时表");
                            this.uiDataGridView已选.Rows[i].Cells["D去向"].Value = 去向;
                        }
                    }
                    else if (this.uiDataGridView已选.Columns[结束列].Name == "D客户")
                    {
                        string 客户;
                        客户 = this.uiTextBox客户.Text;

                        for (int i = 开始行; i <= 结束行; i++)
                        {
                            卷号 = this.uiDataGridView已选.Rows[i].Cells["D热轧批号"].Value.ToString();
                            sql = "update Temp_酸洗计划 set Customer ='" + 客户 + "' where VolumeCodeNew ='" + 卷号 + "' and guid='" + FormGuid + "'";
                            pub.ExecuteSql(pub.ConnectionString, sql, "批量修改=酸洗临时表");
                            this.uiDataGridView已选.Rows[i].Cells["D客户"].Value = 客户;
                        }
                    }
                    else if (this.uiDataGridView已选.Columns[结束列].Name == "D成品规格")
                    {
                        string 成品规格;
                        成品规格 = this.uiTextBox成品规格.Text;
                        if (成品规格 != "")
                        {
                            if (!pub.IsRightSize(成品规格))
                            {
                                MessageBox.Show("成品规格填写错误不能批量修改", "提示", MessageBoxButtons.OK);
                                return;
                            }
                        }

                        for (int i = 开始行; i <= 结束行; i++)
                        {
                            卷号 = this.uiDataGridView已选.Rows[i].Cells["D成品规格"].Value.ToString();
                            sql = "update Temp_酸洗计划 set ProductSize ='" + 成品规格 + "' where VolumeCodeNew ='" + 卷号 + "' and guid='" + FormGuid + "'";
                            pub.ExecuteSql(pub.ConnectionString, sql, "批量修改=酸洗临时表");
                            this.uiDataGridView已选.Rows[i].Cells["D成品规格"].Value = 成品规格;
                        }
                    }
                    else if (this.uiDataGridView已选.Columns[结束列].Name == "D备注")
                    {
                        string 备注;
                        备注 = this.uiTextBox备注.Text.Trim().Replace("--", "");
                        for (int i = 开始行; i <= 结束行; i++)
                        {
                            卷号 = this.uiDataGridView已选.Rows[i].Cells["D热轧批号"].Value.ToString();
                            sql = "update Temp_酸洗计划 set Remark ='" + 备注 + "' where VolumeCodeNew ='" + 卷号 + "' and guid='" + FormGuid + "'";
                            pub.ExecuteSql(pub.ConnectionString, sql, "批量修改=酸洗临时表");
                            this.uiDataGridView已选.Rows[i].Cells["D备注"].Value = 备注;
                        }
                    }
                }
            }
        }

        private void uiComboBox材质1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void uiTextBox产地1_TextChanged(object sender, EventArgs e)
        {

        }

        private void uiTextBox卷号_TextChanged(object sender, EventArgs e)
        {

        }

        private void uiLabel24_Click(object sender, EventArgs e)
        {

        }
    }
}
